package masterlink.util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileUtil {
	public void writeFile(String fileName){
		   FileWriter fw=null; 
		    try{
		      fw = new FileWriter(fileName); 
		      for(int i=0;i<10;i++){ 
		        fw.write("this is "+i+"\n\r"); 
		      }
		    }
		    catch(IOException ioe){ 
		      System.out.println("err : "+ioe.getStackTrace()); 
		    }
		    finally{
		      if(fw!=null){
		        try{
		          fw.close();
		        }
		        catch(IOException ioe){} 
		      }
		    }

	}
	
	public void readFile(String fileName){
	    String str=""; 
	    BufferedReader br=null; 
	    try{
	     //br = new BufferedReader(new FileReader("c:\\aa.txt")); 
	    	br = new BufferedReader(new FileReader(fileName));
	      while(true){
	        str=br.readLine();
	        if(str==null){
	          break;
	        }
	        System.out.println(str);
	      }
	    }
	    catch(FileNotFoundException fnfe){ 
	      System.out.println("not found file "+fnfe.getMessage()); 
	    }
	    catch(IOException ioe){ 
	      System.out.println("ioe err : "+ioe.getMessage()); 
	    }
	    finally{
	      try{
	        if (br != null) { 
	          br.close();
	        }
	      }
	      catch(IOException ioe){} 
	    }

	}
}
